#pragma once

#include "Type.h"

#include "Package.h"

namespace uml {

Type::Type(const QString& umlType)
    : PackageableElement(umlType) {}

void Type::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    PackageableElement::fromJson(json, errorList);
    package_ = JsonSerializable::create<Package>(json.value("package"), errorList);

}

void Type::toJson(QJsonObject& json) {
    PackageableElement::toJson(json);
    if (package_) {
        QJsonObject package_json;
        package_->toJson(package_json);
        json.insert("package", package_json);
    }
}

/// <summary>
/// conformsTo
    /// The query conformsTo() gives true for a Type that conforms to another. By
    /// default, two Types do not conform to each other. This query is intended to be
    /// redefined for specific conformance situations.
/// </summary>
    /// <code>
    /// result = (false)
    /// </code>
bool Type::conformsTo(shared_ptr<Type> other) const
{
    return false;
}

/// <summary>
/// package getter
/// Specifies the owning Package of this Type, if any.
/// </summary>
shared_ptr<Package> Type::package() const {
    return package_;
}

/// <summary>
/// package setter
/// Specifies the owning Package of this Type, if any.
/// </summary>
void Type::setPackage(shared_ptr<Package> value) {
    package_ = value;
}

} // namespace uml
